﻿using System;
using System.Collections.Generic;
using System.Text;

namespace CoNatural.Data.VisualStudio.AddIn.Helpers {
	internal class ModelBuilder {
		private static readonly string csFileTemplate =
@"
//-------------------------------------------------------
//-- {0}.cs
//--
//-- Created by {1} with CoNatural Visual Studio AddIn 
//-- Created on {2}
//-------------------------------------------------------
 
using System;

namespace {3} {{
	public class {0} {{
		public {0}() {{}}
{4}
	}}
}}
";

		private static readonly string csPropertyTemplate =
@"
		public {0} {1} {{ get; set; }}";

		static public string BuildModel(string _namespace, string name, IEnumerable<CoNatural.Data.Helpers.PropertyHelper> properties) {
			var sb = new StringBuilder();
			foreach(var property in properties)
				sb.Append(string.Format(csPropertyTemplate, property.TypeName, property.Name));
			return string.Format(csFileTemplate, name, Environment.UserName, DateTime.Now.ToString(),	_namespace, sb);
		}

		static public string BuildModel(string _namespace, string name, string properties) {
			return string.Format(csFileTemplate, name, Environment.UserName, DateTime.Now.ToString(), _namespace, properties);
		}
	}
}
